package org.example.projecttwo.controller.user;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.example.projecttwo.common.Result;
import org.example.projecttwo.entity.dto.auth.AuditUserAuthDTO;
import org.example.projecttwo.entity.user.UserTypeAuth;
import org.example.projecttwo.service.Iuser.IUserTypeAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/userTypeAuth")
@Tag(name = "用户认证管理", description = "用户类型认证管理")
public class UserTypeAuthController {

    @Autowired
    private IUserTypeAuthService userAuthService;

    @GetMapping("/current")
    @Operation(summary = "获取当前用户认证信息", description = "获取当前登录用户的认证信息 -- 个人信息")
    public Result<UserTypeAuth> getCurrentUserAuth() {
        UserTypeAuth userTypeAuth = userAuthService.getCurrentUserAuth();
        return Result.success(userTypeAuth);
    }

    @PostMapping
    @Operation(summary = "提交用户认证申请", description = "用户提交认证申请 -- 个人信息")
    public Result<String> submitUserAuth(@RequestBody UserTypeAuth userTypeAuth) {
        boolean result = userAuthService.submitUserAuth(userTypeAuth);
        return result ? Result.success("提交成功") : Result.error("提交失败");
    }

    @PutMapping("/{authId}/audit")
    @Operation(summary = "审核用户认证", description = "管理员审核用户的认证申请 -- 用户管理")
    public Result<String> auditUserAuth(@Parameter(description = "认证ID") @PathVariable Long authId, @RequestBody AuditUserAuthDTO dto) {
        boolean result = userAuthService.auditUserAuth(authId, dto.getStatus(), dto.getRejectReason());
        return result ? Result.success("审核成功") : Result.error("审核失败");
    }

    @GetMapping("/{authId}")
    @Operation(summary = "获取用户认证信息", description = "根据认证ID获取用户的认证信息 -- 用户管理")
    public Result<UserTypeAuth> getUserAuth(@Parameter(description = "认证ID") @PathVariable Long authId) {
        UserTypeAuth userTypeAuth = userAuthService.getById(authId);
        return Result.success(userTypeAuth);
    }

}